home *** CD-ROM | disk | FTP | other *** search
- /* NAME:
- ES Handler.c
-
- WRITTEN BY:
- Dair Grant
-
- DESCRIPTION:
- This file contains an ES Handler for use by Extension Shell.
-
- ___________________________________________________________________________
- */
- //=============================================================================
- // Include files
- //-----------------------------------------------------------------------------
- #include <Gestalt.h>
- #include "A4Stuff.h"
- #include "SetupA4.h"
- #include "ES.h"
- #include "WK Constants.h"
- #include "ES Handler.h"
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //=============================================================================
- // Private function prototypes
- //-----------------------------------------------------------------------------
- void main(short theMsg, ESParamBlock *theParamBlock);
- void InitialiseParamBlock(void);
- void InitialiseAddrsTable(void);
- void HandleTheError(void);
- void SetUpIcons(short animDelay, short numIcons, short firstIcon);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //=============================================================================
- // Global variables
- //-----------------------------------------------------------------------------
- ESParamBlock *gTheParamBlock;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //=============================================================================
- // main : Entry point to our code resource.
- //-----------------------------------------------------------------------------
- // Note : Extension Shell communicates with us via a message constant,
- // and a pointer to a structure it owns. Our job is to fill in
- // the details in that structure, depending on what it wants us
- // to do.
- //-----------------------------------------------------------------------------
- void main(short theMsg, ESParamBlock *theParamBlock)
- { long oldA4;
-
-
-
- // Set up A4 so that we can access our globals
- #ifndef powerc
- oldA4 = SetCurrentA4();
- #endif
- gTheParamBlock = theParamBlock;
-
-
-
- // Case out on what we have to do
- switch(theMsg) {
- case kInitialiseParamBlock:
- InitialiseParamBlock();
- break;
-
- case kInitialiseAddrsTable:
- InitialiseAddrsTable();
- break;
-
- case kHandleError:
- HandleTheError();
- break;
-
- default:
- ;
- }
-
-
- // Restore A4
- #ifndef powerc
- SetA4(oldA4);
- #endif
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //=============================================================================
- // InitialiseParamBlock : Initialises the ParamBlock.
- //-----------------------------------------------------------------------------
- // Note : We have three tasks to perform.
- // • Check to see if we can run
- // • Set up the icons we want to display
- // • Set up the code we want installed
- //-----------------------------------------------------------------------------
- void InitialiseParamBlock(void)
- {
-
-
- // Check for System 7. We depend on having System 7, and won't
- // run if we don't have it. If we don't have it, we beep, post
- // an error message, and show our disabled icon(s).
- if (gTheParamBlock->systemVersion < 0x0700)
- {
- // Error details
- gTheParamBlock->beepNow = true;
- gTheParamBlock->postError = true;
- gTheParamBlock->errorStringsID = kErrorStrings;
- gTheParamBlock->errorStringIndex = kNeedSystemSeven;
-
-
- // Icon details
- SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
- }
-
-
-
- // If a shift key, or the mouse button, is down, we don't load either.
- // We don't post an error, but we do show our disabled icon(s) to let
- // the user know they've turned us off.
- else if ((*gTheParamBlock->IsKeyMouseDown)(kShiftKey, true))
- {
- // Icon details
- SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
- }
-
-
-
- // Otherwise, we're allowed to run. If we had a Control Panel, we
- // would also check to see if our Control Panel had turned us
- // off (by setting some preference resource).
- else
- {
- // Icon details
- SetUpIcons(kEnabledAnimDelay, kMyNumEnabledIcons, kMyFirstEnabledIcon);
-
-
- // We install one code resource, and use an address table (the default
- // address table, since we only need a slot to hold the address of
- // the previous head of the jGNEFilter chain).
- gTheParamBlock->installAddressTable = true;
- gTheParamBlock->addressTableSelector = kWhatKeyAddressTable;
- gTheParamBlock->numCodeResources = 1;
-
-
- // Details for our jGNEFilter routine.
- gTheParamBlock->theCodeResources[kWhatKey].resType = kWhatKeyResType;
- gTheParamBlock->theCodeResources[kWhatKey].resID = kWhatKeyResID;
- gTheParamBlock->theCodeResources[kWhatKey].codeType = kLowMemFilterType;
- gTheParamBlock->theCodeResources[kWhatKey].theCodeThing.theLowMemFilter.theEntryPoint = kJGNEFilterAddress;
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //=============================================================================
- // InitialiseAddrsTable : Initialise the address table.
- //-----------------------------------------------------------------------------
- // Note : If we requested an address table, Extension Shell calls us back
- // to allow us to initialise any extensions we've made to it.
- //
- // This routine will only be called if we request an address
- // table, and is called after the address table is installed,
- // but before any of the items in gTheParamBlock->theCodeResources
- // are processed (since they might need to access the address
- // table).
- //
- // We should initialise the magicNumber and versionNumber fields
- // with constants fixed for this build. One possible number for the
- // magicNumber field would be sizeof() our address table structure.
- //-----------------------------------------------------------------------------
- void InitialiseAddrsTable(void)
- {
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //=============================================================================
- // HandleTheError : Handle any errors
- //-----------------------------------------------------------------------------
- // Note : This routine is called if an error occurred during the
- // installation of the items in gTheParamBlock->theCodeResources.
- //
- // If an error occurs we beep, post an error, and request that
- // as much as possible of our code be uninstalled. We also reset
- // the icon details to show our disabled icons.
- //-----------------------------------------------------------------------------
- void HandleTheError(void)
- {
-
-
- // Decide how we want to handle the error
- gTheParamBlock->removeInstalledCode = true;
- gTheParamBlock->beepNow = true;
- gTheParamBlock->postError = true;
- gTheParamBlock->errorStringsID = kErrorStrings;
-
-
- // Message to display to the user
- gTheParamBlock->errorStringIndex = kUnknownError;
-
-
- // Icon details
- SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- //=============================================================================
- // SetUpIcons : Set up our the icon fields in gTheParamBlock.
- //-----------------------------------------------------------------------------
- // Note : We are passed in the resource ID of the first icon, the number
- // of icons, and a delay for animation. We fill these details
- // in to gTheParamBlock.
- //-----------------------------------------------------------------------------
- void SetUpIcons(short animDelay, short numIcons, short firstIcon)
- { short i;
-
-
- gTheParamBlock->animationDelay = animDelay;
- gTheParamBlock->numIcons = numIcons;
- for (i = 1; i <= numIcons; i++)
- gTheParamBlock->theIcons[i] = firstIcon + i - 1;
- }
-